package com.ssca.redis;

import java.io.IOException;
import java.net.SocketException;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;

public class FtpClient {
	private static String IP = "192.168.1.184";
	private static String USER = "taseUser";
	private static String PWD = "62283748";

	
	public static void getFileList(String remoteFileRoot){
		FTPClient ftpClient = new FTPClient();
		try {
			ftpClient.connect(IP);
			ftpClient.login(USER, PWD);
			int reply = ftpClient.getReplyCode();
			
			ftpClient.changeWorkingDirectory(remoteFileRoot);
			
			FTPFile[]files = ftpClient.listFiles();
			for(FTPFile file : files){
				if(!file.isDirectory()){
					if(file.getName().endsWith(".apk"))
						JedisUtil.lpush("ftp_file", remoteFileRoot+"/"+file.getName());
				}
				else{
					getFileList(remoteFileRoot+"/"+file.getName());
				}
			}
			
			
		} catch (SocketException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				ftpClient.disconnect();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
		}
	}
	
	public static void main(String[] args) {
		new FtpClient().getFileList(args[0]);
//		new FtpClient().getFileList("/20160429/3");
	}
}
